package com.xfly.app.ui;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.ptmall.app.R;
import com.ptmall.app.base.BaseMvpActivity;
import com.ptmall.app.base.theme.Eyes;
import com.ptmall.app.net.api.ApiDataRepository;
import com.ptmall.app.net.base.ApiNetResponse;
import com.ptmall.app.ui.adapter.OrderGoodAdapter;
import com.ptmall.app.utils.GlideUtil;
import com.ptmall.app.utils.TimeUtil;
import com.ptmall.app.view.NoScrollListView;
import com.xfly.app.bean.OrderBean;

import java.util.HashMap;
import java.util.Map;

public class XfOrderDetilActivity extends BaseMvpActivity
{
    ImageView back;
    TextView statustext2,statustext1;
    TextView address,addressphone,addressname,shopname;
    TextView yf,sfk,bz,bh,time,timetitle,paytype,paytime,htsc,httitle;
    LinearLayout htlin;
    ImageView htimg;
    NoScrollListView listview;
    LinearLayout paytimelin,paytypelin;
    ApiDataRepository apiDataRepository = ApiDataRepository.getInstance();
    OrderGoodAdapter orderGoodAdapter;
    String id = "";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setView(R.layout.activity_xforderdetil);

        Eyes.setStatusBarLightMode(this, 0xffFD5966);
    }

    @Override
    public void initViews() {
        id = getIntent().getStringExtra("id");
        back = findViewById(R.id.back);
        statustext1 = findViewById(R.id.statustext1);
        statustext2 = findViewById(R.id.statustext2);
        address = findViewById(R.id.address);
        addressphone = findViewById(R.id.addressphone);
        addressname = findViewById(R.id.addressname);
        shopname = findViewById(R.id.shopname);
        listview = findViewById(R.id.listview);
        yf = findViewById(R.id.yf);
        sfk = findViewById(R.id.sfk);
        bz = findViewById(R.id.bz);
        bh = findViewById(R.id.bh);
        time = findViewById(R.id.time);
        timetitle = findViewById(R.id.timetitle);
        paytype = findViewById(R.id.paytype);
        paytime = findViewById(R.id.paytime);
        paytypelin = findViewById(R.id.paytypelin);
        paytimelin = findViewById(R.id.paytimelin);
        htsc = findViewById(R.id.htsc);
        htlin = findViewById(R.id.htlin);
        httitle = findViewById(R.id.httitle);
        htimg = findViewById(R.id.htimg);
    }

    @Override
    public void initEvents() {
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        htsc.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(getContext(),SubHtActivity.class);
                intent.putExtra("id",id);
                startActivity(intent);
                finish();
            }
        });
        getDetil();
    }

    private void getDetil(){
        Map<String,String> map = new HashMap<>();
        map.put("orders_id",id);
        apiDataRepository.getorderinfo(map, new ApiNetResponse<OrderBean>() {
            @Override
            public void onSuccess(OrderBean data) {
                addressname.setText(data.getAddress_name()+"");
                addressphone.setText(data.getAddress_phone()+"");
                address.setText(data.getAddress_address()+"");
//                shopname.setText(data.getSupplier()+"");
                orderGoodAdapter = new OrderGoodAdapter(getContext(),data.getGoods());
                listview.setAdapter(orderGoodAdapter);
                switch (data.getStatus()){
                    case 0:
                        statustext1.setText("等待支付");
                        break;
                    case 1:
                        statustext1.setText("等待发货");
                        break;
                    case 2:
                        statustext1.setText("配送中");
                        break;
                    case 3:
                        statustext1.setText("已完成");
                        break;
                    case 4:
                        statustext1.setText("退款售后");
                        break;
                }
//                bz.setText(data.ge);
                bh.setText(data.getOrderno()+"");
                if(data.getPaytime()>0){
                    paytime.setText(TimeUtil.getStrTime(data.getPaytime()+""));
                    switch (data.getPayway()){
                        case "money":
                            paytype.setText("余额支付");
                            break;
                        case "alipay":
                            paytype.setText("支付宝支付");
                            break;
                        case "weixin":
                            paytype.setText("微信支付");
                            break;
                        case "bank":
                            paytype.setText("银联支付");
                            break;
                        case "face":
                            paytype.setText("货到付款");
                            break;
                    }
                }else {
                    paytimelin.setVisibility(View.GONE);
                    paytypelin.setVisibility(View.GONE);
                }
                time.setText(TimeUtil.getStrTime(data.getCreate_time()+""));
                if(TextUtils.isEmpty(data.getContract_title())){
                    htlin.setVisibility(View.GONE);
                }else {
                    htlin.setVisibility(View.VISIBLE);
                    GlideUtil.showImg(getContext(),data.getContract()+"",htimg);
                    httitle.setText(data.getContract_title()+"");
                }
            }
        });
    }
}
